<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>回收价格</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.qrcode.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/public.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style type="text/css">
        .layui-form-label {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 200px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
        }
        .layui-input-block {
            margin-left: 200px;
            min-height: 36px;
        }
    </style>
</head>
<body>


<form class="layui-form" id="addchannel" lay-filter="addchannel">
    <div class="layui-form-item">
        <label class="layui-form-label">*纸板价格(元)：</label>
        <div class="layui-input-inline">
            <input type="text" name="zb" id="zb" lay-verify="required"  placeholder="" autocomplete="off" class="layui-input">
            <input type="hidden" id="zbid" name="zbid">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">*塑料价格(元)：</label>
        <div class="layui-input-inline">
            <input type="text" name="sl" id="sl" lay-verify="required"  autocomplete="off" class="layui-input">
            <input type="hidden" id="slid" name="slid">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">*泡沫(元)：</label>
        <div class="layui-input-inline">
            <input type="text" name="pm" id="pm" lay-verify="required"  autocomplete="off" class="layui-input">
            <input type="hidden" id="pmid" name="pmid">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>



<script src="../layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>


    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
        $=layui.$;
        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,number : [/(^[0-9]{1,2}$)|(^[0-9]{1,2}[\.]{1}[0-9]{1,2}$)/, '必须输入数字啊']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        $.ajax({
            type: "get",
            dataType: "json",
            url: "/refuse-web/api/refuse/types",
            async: true,
            data: {
                code: "recyclable"

            },
            success: function(data) {
                var map=data;
                if(map.code==0) {
                    form.val('addchannel', {
                        "zb": map.data[0].price // "name": "value"
                        ,"zbid": map.data[0].id
                        ,"sl": map.data[1].price
                        ,"slid": map.data[1].id //复选框选中状态
                        ,"pm": map.data[2].price //开关状态
                        ,"pmid": map.data[2].id

                    });
                    // $("zb").val(map.data[0].name);
                    // $("zbid").val(map.data[0].id);
                    // $("sl").val(map.data[1].name);
                    // $("slid").val(map.data[1].id);
                    // $("pm").val(map.data[2].name);
                    // $("pmid").val(map.data[2].id);

                } else {
                    layer.msg(map.msg);
                }
            },
            error: function(msg) {
                alert("服务器请求失败！");
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交

        form.on('submit(demo1)', function(data){
            var zb=$("#zb").val();
            var zbid=$("#zbid").val();
            var sl=$("#sl").val();
            var slid=$("#slid").val();
            var pm=$("#pm").val();
            var pmid=$("#pmid").val();
            $.ajax({
                type:"post",
                dataType:"json",
                url:"/refuse-web/api/refuse/updatejfgz",
                async: true,
                data: {
                    zb:zb,
                    zbid: zbid,
                    sl:sl,
                    slid:slid,
                    pmid:pmid,
                    pm:pm

                },
                success: function(data) {
                    if(data.code==0) {
                        alert("成功!");

                    } else {
                        alert(data.msg);
                    }
                },
                error: function(msg) {
                    alert("服务器请求失败！");
                }
            });


            return false;
        });


    });
</script>

</body>
</html>